package com.beney.messageHandler;

import com.beney.codec.MessagePacket;
import com.beney.message.MessageHandler;
import com.beney.message.idle.HearbeatReq;
import com.beney.message.idle.HeartbeatResp;
import io.netty.channel.Channel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Component
public class HeartbeatReqHandler implements MessageHandler<HearbeatReq> {

    private Logger logger = LoggerFactory.getLogger(getClass());

    @Override
    public void handle(Channel ch, HearbeatReq message) {
        logger.info("[handle][收到连接 ({}) 的心跳请求]", ch.id());
        HeartbeatResp resp = new HeartbeatResp();
        ch.writeAndFlush(new MessagePacket(HeartbeatResp.TYPE, resp));
    }

    @Override
    public String messageType() {
        return HearbeatReq.TYPE;
    }
}
